const {
  $util,
} = getApp();
const myaudio = wx.createInnerAudioContext();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loaded: false,
    isplay: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData(options);
    this.loadDetail();
  },
  /**
   * 详情
  */
  loadDetail() {
    $util.request({
      url: `entry/wxapp/edu.train.${this.data.typ}`,
      data: {
        id: this.data.id,
      },
      success: (res) => {
        if (res.list && res.list.video) {
          const radio = res.list.video.split('.');
          res.list.isvideo = radio[radio.length - 1];
          myaudio.src = res.list.video;
        }
        res.list.loaded = true;
        this.setData(res.list);
        wx.setNavigationBarTitle({
          title: res.list.name || res.list.title || '',
        });
      },
    });
  },
  audioPlay(e) {
    myaudio.play();
    this.setData({
      isplay: true,
    });
    console.log('播放');
  },
  audioPaused(e) {
    myaudio.pause();
    this.setData({
      isplay: false,
    });
    console.log('暂停');
  },
  onUnload() {
    myaudio.destroy();
  },
});
